package com.greatwall.hip.cms.util;

import com.google.common.collect.Maps;
import com.greatwall.hip.cms.constant.MonitorPreCategoryEnum;
import com.greatwall.hip.cms.entity.LyDiseaseSymptom;
import com.greatwall.hip.cms.entity.LyDiseaseTag;
import com.greatwall.hip.cms.entity.LyPacsReport;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/**
 * @author ljl
 * @date 2021/7/8 11:55
 **/
public class MonitorCacheUtil {

    /**
     * 疾病病症缓存数据
     */
    private static final HashMap<String, List<LyDiseaseTag>> DISEASE_LAST_MONTH_CACHE_DATA = Maps.newHashMap();

    /**
     * 症状
     */
    private static final HashMap<String, List<LyDiseaseSymptom>> SYMPTOM_LAST_MONTH_CACHE_DATA = Maps.newHashMap();

    /**
     * 影像缓存数据
     */
    private static final HashMap<String, List<LyPacsReport>> PACS_REPORT_LAST_MONTH_CACHE_DATA = Maps.newHashMap();

    /**
     * 影像缓存数据
     */
    private static final HashMap<String, List<LyPacsReport>> CHILD_PACS_REPORT_LAST_MONTH_CACHE_DATA = Maps.newHashMap();

    public static <T> void put(String date, List<T> cache, MonitorPreCategoryEnum category) {
        switch (category) {
            case DISEASE:
                DISEASE_LAST_MONTH_CACHE_DATA.put(date, (List<LyDiseaseTag>) cache);
                break;
            case SYMPTOM:
                SYMPTOM_LAST_MONTH_CACHE_DATA.put(date, (List<LyDiseaseSymptom>) cache);
                break;
            case PACS_REPORT_ABNORMAL:
                PACS_REPORT_LAST_MONTH_CACHE_DATA.put(date, (List<LyPacsReport>) cache);
                break;
            case CHILD_PACS_REPORT_ABNORMAL:
                CHILD_PACS_REPORT_LAST_MONTH_CACHE_DATA.put(date, (List<LyPacsReport>) cache);
                break;
            default:
                break;
        }
    }

    public static <T> List<T> get(String date, MonitorPreCategoryEnum category) {
        switch (category) {
            case DISEASE:
                return (List<T>) DISEASE_LAST_MONTH_CACHE_DATA.get(date);
            case SYMPTOM:
                return (List<T>) SYMPTOM_LAST_MONTH_CACHE_DATA.get(date);
            case PACS_REPORT_ABNORMAL:
                return (List<T>) PACS_REPORT_LAST_MONTH_CACHE_DATA.get(date);
            case CHILD_PACS_REPORT_ABNORMAL:
                return (List<T>) CHILD_PACS_REPORT_LAST_MONTH_CACHE_DATA.get(date);
            default:
                return Collections.emptyList();
        }
    }

    public static void clear() {
        DISEASE_LAST_MONTH_CACHE_DATA.clear();
        SYMPTOM_LAST_MONTH_CACHE_DATA.clear();
        PACS_REPORT_LAST_MONTH_CACHE_DATA.clear();
        CHILD_PACS_REPORT_LAST_MONTH_CACHE_DATA.clear();
    }

}
